﻿#include "MaterialFEWapper.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEModel.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"

FE* MaterialFEWapper::new_FE()
{
    FE* fe = new FE;
    this->init(fe);
    return fe;
}
void MaterialFEWapper::delete_FE(FE * obj)
{
    if (obj) delete obj;
}

FE * MaterialFEWapper::static_FE_GetFE(const QString & name)
{
    FE* fe = new FE(name);
    this->init(fe);
    return fe;
}

QString MaterialFEWapper::getName(FE * obj)
{
    if (obj)
        return obj->getName();
    return QString();
}

void MaterialFEWapper::setName(FE * obj, const QString & name)
{
    if (!obj)return;
    bool ok = obj->setName(name);
    if (!ok) {
        AppFrame::FITKMessageError("set Name failed !");
    }
}

void MaterialFEWapper::setField(FE * obj, int type, double value)
{
    if (!obj)return;
    bool ok = obj->setField(type, value);
    if (!ok) {
        AppFrame::FITKMessageError("set Property failed !");
    }
}

void MaterialFEWapper::createMaterial(FE * obj, const QString & name)
{
    if (!obj)return;
    bool ok = obj->createMaterial(name);
    if (!ok) {
        AppFrame::FITKMessageError("Create FE Material failed !");
    }
}

void MaterialFEWapper::init(FE * obj)
{
    if (!obj)return;
    Acoustics::FITKAcousticsDiscModel* model= Acoustics::FITKAcousticsDiscModel::GetDiscModelFromFrame();
    if (!model)return;
    Acoustics::FITKAcousticsFEModel* feModel = model->getFEModel();
    if (!feModel)return;
    auto mgr = feModel->getMaterialManager();
    if (!mgr)return;
    obj->setMaterialManager(mgr);
}

FE::FE(const QString & name):
    Acoustics::PyFITKMaterialsFE(name)
{
}

FE::FE():
    Acoustics::PyFITKMaterialsFE()
{
}
